<template>
  <el-container>
    <el-form  :model="jkwhbData"  label-position="right" label-width="150px" style="width:100%;text-align: center"  ref="jkwhb" >
      <h3 :labelName="labelName">{{labelName}}</h3>
      <el-form-item label="物质编码" prop="1">
        <el-input v-model="jkwhbData.baseinfoWzbm"  :disabled="true"  ></el-input>
      </el-form-item>
      <el-form-item label="试验生物种属"  prop="2">
        <el-input v-model="jkwhbData.species" placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item label="试验时间" prop="3">
        <el-input v-model="jkwhbData.time"   placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="效应类型" prop="4">
        <el-input v-model="jkwhbData.type" placeholder="请输入内容" ></el-input>
      </el-form-item>
      <el-form-item label="效应值单位" prop="5">
        <el-input v-model="jkwhbData.unit" placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="效应值" prop="6">
        <el-input v-model="jkwhbData.value"   placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="致癌性LARC分类" prop="7">
        <el-input v-model="jkwhbData.zax"   placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="试验方法" prop="8">
        <el-input v-model="jkwhbData.method"   placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="实测/预测" prop="9">
        <el-input v-model="jkwhbData.shiceyuce" placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="数据来源" prop="10">
        <el-input v-model="jkwhbData.source" placeholder="请输入内容" ></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="11">
        <el-input v-model="jkwhbData.remark" placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item prop="12">
        <el-button type="primary" style="margin-top: 12px;" @click="method"  :btName="btName">{{btName}}</el-button>
      </el-form-item>
    </el-form>
  </el-container>
</template>

<script>
  export default {
    name: "Jkwhb",
    props: {
      elementId: {
        type: String,
        default: ''
      },
      perms: '',
      labelName:'',
      btName:'',
      showdata:{}
    },
    data() {
      return {
        jkwhbData: {
          'attribute':'',
          'baseinfoWzbm': '',
          'id': '',
          'species':'',
          'time':'',
          'type':'',
          'unit': '',
          'value': '',
          'zax': '',
          'method': '',
          'shiceyuce': '',
          'source':'',
          'remark': '',
          'flag': '',
          'lastid': ''
        },
        findParams:{
          elementId:'',
          labelName:'',
          flag:''
        },
        addParams:{
          labelName:''
        },
      }
    },
    watch: {
      elementId(value) {
      }
    },
    mounted() {
      console.log('elementID:' + this.elementId)
      console.log(this.perms)
      this.$nextTick(()=>{
        this.$refs['jkwhb'].resetFields()}
      )
      this.jkwhbData=this.showdata
    },
    methods: {
      queryElement: function () {
        console.log(this.labelName)
        this.findParams.elementId=this.elementId
        this.findParams.labelName=this.labelName
        this.findParams.flag = 1
        console.log( this.findParams.flag)
        this.$api.addrecord.findByIdAndFlagInJkwhb(this.findParams).then(res => {
          this.jkwhbData = res.data[0]
          console.log(res.data[0])
        })

      },
      modifyId:function(){
        this.jkwhbData.id=this.perms+Date.now()
      },
      modifyAuthority:function(){
        if(this.perms==='admin'){
          this.jkwhbData.flag=1
        }else{
          if(this.btName==="新增") {
            this.jkwhbData.flag=0
          }else{
            this.jkwhbData.flag=2
          }
        }
      },
      save:function() {
        this.modifyAuthority()
        this.addParams.labelName=this.labelName
        if(this.btName ==="新增") {
          this.modifyId()
          this.$api.addrecord.addRecordInJkwhb(this.jkwhbData, this.addParams).then(res => {
            alert("新增成功！")
          })
        } else{
          this.jkwhbData.lastid=this.jkwhbData.id
          this.modifyId()
          this.$api.addrecord.addRecordInJkwhb(this.jkwhbData, this.addParams).then(res => {
            alert("纠错成功！待审核")
          })
        }
      },
      update:function () {
        this.modifyAuthority()
        this.$api.addrecord.updateInJkwhb(this.jkwhbData).then(res => {
          alert("更新成功！")
        })
        //删除操作
      },
      method:function () {
        if(this.btName==="更新"){
          this.update()
        }else {
          this.save()
        }
      }

    }
  }

</script>

<style scoped>

</style>


